/**
 * 地址映射
 * @author luguoxiang
 * @date 2025-05-10
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { createCache } from 'lg.cache';
import { createApi, request } from '@/soar';

export const basePath = '/system/url-mapping';
export const subject = '地址映射';

// 创建缓存
const cache = createCache({
  name: 'urlMapping',
  loader(key: string) {
    return request.get(`${basePath}/getByGroup?group=${key}`);
  },
});

const api = {
  ...createApi(basePath, subject),
  /**
   * 根据分组获取地址映射
   * @param group 分组
   */
  getByGroup: (group: string) => cache.load(group),
  /**
   * 获取路径
   * @param group
   * @param bizType
   */
  getUrl(group: string, bizType: string) {
    return this.getByGroup(group).then((res: any) => {
      return res[bizType];
    });
  },
  /**
   * 获取全部地址映射
   */
  getMapping: () => request.get(`${basePath}/getByGroup`),
  clearCache: () => request.post(`${basePath}/clear-cache`),
  getGroups: () => request.get(`${basePath}/getGroups`),
  getBizTypes: () => request.get(`${basePath}/getBizTypes`),
};

export default api;
